using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NTTHAO.Common;
using NTTHAO.CommonWeb;
using NTTHAO.Web.BL.Contact;

public partial class admin_webparts_Plug_ins_Contact_ContactList : System.Web.UI.UserControl
{
    public static readonly int PAGE_SIZE = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["NUM_ROW_PER_PAGE"]);
    public int _PageNo = 1;
    public int _PageCount = 1;
    public long _TotalItem = -1;
    public string _PageUrl = "";

    public ContactGroup _Group = null;
    public DataTable _List = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["page"] != null)
        {
            try
            {
                _PageNo = Convert.ToInt32(Request.QueryString["page"].Trim());
            }
            catch { }
        }

        try
        {
            for (int i = 0; i < Request.QueryString.Count; i++)
            {
                if (!"page".Equals(Request.QueryString.GetKey(i), StringComparison.OrdinalIgnoreCase)
                    && !"time".Equals(Request.QueryString.GetKey(i), StringComparison.OrdinalIgnoreCase))
                {
                    _PageUrl += "&" + Request.QueryString.GetKey(i) + "=" + Server.UrlEncode(Request.QueryString[i]);
                }
            }
            if (_PageUrl.Length > 0)
            {
                _PageUrl = "?" + _PageUrl.TrimStart('&');
            }
        }
        catch { }

        try
        {
            int id = Convert.ToInt32(Request.QueryString["id"]);
            _Group = new ContactGroup(id);
            _List = ContactDetail.GetPage(_Group.ID, _PageNo, PAGE_SIZE, ref _TotalItem);

            this._PageCount = (int)(this._TotalItem / PAGE_SIZE + (this._TotalItem % PAGE_SIZE != 0 ? 1 : 0));
            this._PageCount = this._PageCount < 1 ? 1 : this._PageCount;
            _PageUrl += (_PageUrl.Length > 0 ? "&" : "?") + "time=" + DateTime.Now.Ticks.ToString() + "&";
        }
        catch (Exception)
        { }
    }
}
